<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p></p>
    <script>
        // 原有数据：
        let str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        let arr = [];
        let cites = [{
                py: 'beijing',
                name: '北京'
            }, {
                py: 'alishan',
                name: '阿里山'
            }, {
                py: 'beidaihe',
                name: '北戴河'
            }, {
                py: 'shijiazhuang',
                name: '石家庄'
            }, {
                py: 'anhui',
                name: '安徽'
            }, {
                py: 'shanxi',
                name: '陕西'
            }, {
                py: 'sichuan',
                name: '四川'
            }, {
                py: 'shenzhen',
                name: '深圳'
            }, {
                py: 'chengdu',
                name: '成都'
            }]
            // 需要生成的数据：
            // {A: [{py: 'alishan',name: '阿里山'}],B: [{py: 'beijing',name: '北京'}, {py: 'beidaihe',name: '北戴河'}],}

        // 提示：
        let obj1 = {}
        arr = str.split('');
        for (let i = 0; i < arr.length; i++) {
            obj1[arr[i]] = [];
            for (let j = 0; j < cites.length; j++) {
                if (arr[i] == cites[j].py[0].toLocaleUpperCase()) {
                    obj1[arr[i]].push(cites[j]);

                };
            };
        };
        // console.log(obj1);
        // 1. 根据str 生成  obj = { A: [], B: [], C: []...Z: []}
        // 2. 根据cites 里py中的第一个字母，作为obj对象的属性名
    </script>
</body>

</html>